﻿<phone:PhoneApplicationPage 
    x:Class="mal.WP7.GoogleAnalytics.EditAccountPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:mal.WP7.GoogleAnalytics"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="728" d:DesignWidth="480"
    shell:SystemTray.IsVisible="False">
	<phone:PhoneApplicationPage.Resources>
		<ControlTemplate x:Key="PhoneDisabledTextBoxTemplate" TargetType="TextBox">
			<ContentControl x:Name="ContentElement" BorderThickness="0" HorizontalContentAlignment="Stretch" Margin="{StaticResource PhoneTextBoxInnerMargin}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="Stretch"/>
		</ControlTemplate>
		
	</phone:PhoneApplicationPage.Resources>

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <local:HeaderBackground Grid.RowSpan="2" VerticalAlignment="Top" />


        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Style="{StaticResource TitlePanelStyle}"
                   >
            <TextBlock x:Name="ApplicationTitle" 
                       Text="{Binding Text.ApplicationName, Source={StaticResource Resource}}" 
                       Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock Text="{Binding Text.AccountPageTitle, Source={StaticResource Resource}}" 
                       Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <StackPanel x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"
              VerticalAlignment="Top">


            <StackPanel Orientation="Horizontal" Grid.Column="0" Grid.Row="0" >
                <TextBlock Text="{Binding Text.AccountPageLogin
                        , Source={StaticResource Resource}}" />

                <!--<TextBlock Foreground="Red" Text="{Binding LoginErrorMessage}"
                           Visibility="{Binding PasswordIsValid, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=inverse}"/>-->
            </StackPanel>
            <Grid  Grid.Column="1" Grid.Row="0">
                <Border BorderBrush="Red" BorderThickness="1" 
                        Visibility="{Binding Account.LoginIsvalid, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=inverse}" />
                <TextBox Text="{Binding Account.Login, Mode=TwoWay}"
                     KeyUp="TextBox_KeyUp" >
                    <TextBox.InputScope>
                        <InputScope >
                            <InputScopeName NameValue="EmailUserName"/>
                        </InputScope>
                    </TextBox.InputScope>
                </TextBox>
            </Grid>            

            <StackPanel Orientation="Horizontal" Grid.Column="0" Grid.Row="1" >
                <TextBlock Text="{Binding Text.AccountPagePassword
                        , Source={StaticResource Resource}}"  />
                
                <!--<TextBlock Foreground="Red" Text="The password can not be empty"
                           Visibility="{Binding PasswordIsValid, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=inverse}"/>-->
            </StackPanel>

            <Grid  Grid.Column="1" Grid.Row="1" >
                <Border BorderBrush="Red" BorderThickness="1" 
                        Visibility="{Binding Account.PasswordIsValid, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=inverse}" />
                <PasswordBox   
                            Password="{Binding Account.Password, Mode=TwoWay}"
                            KeyUp="TextBox_KeyUp" />
            </Grid>


            <TextBlock Foreground="Green"
                Visibility="{Binding IsLoginSuccess, Converter={StaticResource BoolToVisibilityConverter}}"
                Text="{Binding Text.AccountPageLoginSuccess
                        , Source={StaticResource Resource}}" />

            <TextBlock Foreground="Red"
                       Visibility="{Binding IsLoginFailed, Converter={StaticResource BoolToVisibilityConverter}}"
                       Text="{Binding Text.AccountPageLoginFailled
                        , Source={StaticResource Resource}}" />
        </StackPanel>
        
        <Button Grid.Row="1"
                VerticalAlignment="Bottom" 
                HorizontalAlignment="Left"
                IsEnabled="{Binding Account.IsValid}"
                Command="{Binding TestConnexionCommand}"
                Content="{Binding Text.AccountPageTestButton
                        , Source={StaticResource Resource}}" />
        
        
        <Border Grid.RowSpan="2" Grid.Row="0" Background="Transparent"
                VerticalAlignment="Center" 
                Visibility="{Binding IsLoading, Converter={StaticResource BoolToVisibilityConverter}}">
            
            <StackPanel>
                <ProgressBar IsIndeterminate="True"                          
                         VerticalAlignment="Center"/>
                <TextBlock 
                    HorizontalAlignment="Center"
                    Style="{StaticResource PhoneTextSmallStyle}"
                       Text="{Binding Text.Loading
                        , Source={StaticResource Resource}}" />
            </StackPanel>
            
        </Border>
    </Grid>

    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
           
            <!--<shell:ApplicationBarIconButton x:Name="saveButton"
                                            IconUri="/Images/appbar.save.rest.png" 
                                            Text="enregistrer" 
                                            Click="OnSaveClick"/>-->
            <shell:ApplicationBarIconButton x:Name="deleteButton"
                                            IconUri="/Images/appbar.delete.rest.png" 
                                            Text="supprimer"
                                            Click="OnDeleteClick"/>
            <!--<shell:ApplicationBarIconButton x:Name="closeButton"
                                            IconUri="/Images/appbar.close.rest.png" 
                                            Text="fermer" 
                                            Click="OnCloseClick"/>-->    
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

</phone:PhoneApplicationPage>
